package com.atguigu.yygh.common.utils;

import org.apache.commons.codec.binary.Base64;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * @author ybl
 * @version 1.9
 * @date 2021/5/17 12:07
 */
public class ImageBase64Util {

  // 把base64生成的编码空格变为加号
  public static String getImageString(String imageFile){
    InputStream is = null;
    try {
      byte[] data = null;
      is = new FileInputStream(new File(imageFile));
      data = new byte[is.available()];
      is.read(data);
      return new String(Base64.encodeBase64(data));
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (null != is) {
        try {
          is.close();
          is = null;
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
    return "";
  }

}
